package com.designoutput.ui.options.components
{
	import com.designoutput.enum.TextVAlign;
	import com.designoutput.enum.ToolType;
	import com.designoutput.icon.TextBottomIcon;
	import com.designoutput.icon.TextMiddleIcon;
	import com.designoutput.icon.TextRightIcon;
	import com.designoutput.icon.TextTopIcon;
	import com.designoutput.ui.controls.ToolButton;
	import com.designoutput.ui.options.TextOption;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class TextVAlignGroup extends Sprite
	{
		private var baseOption:TextOption;
		private var top:ToolButton;
		private var middle:ToolButton;
		private var bottom:ToolButton;
		internal var at:ToolButton;
		
		private var _textVAlign:String = TextVAlign.TOP;
		
		public function TextVAlignGroup(baseOption:TextOption)
		{
			this.baseOption = baseOption;
			this.build();
		}
		

		private function build():void{
			
			top= new ToolButton(ToolType.TextTop, new TextTopIcon(0,0),5,5);
			top.addEventListener(MouseEvent.MOUSE_DOWN, this.ToolMouseDown);
			top.x = 0;
			top.y = 10;
			this.addChild(top);
			
			middle = new ToolButton(ToolType.TextMiddle, new TextMiddleIcon(0,0),5,5);
			middle.addEventListener(MouseEvent.MOUSE_DOWN, this.ToolMouseDown);
			middle.x = 30;
			middle.y = 10;
			this.addChild(middle);
			
			bottom = new ToolButton(ToolType.TextBottom, new TextBottomIcon(0,0),5,5);
			bottom.addEventListener(MouseEvent.MOUSE_DOWN, this.ToolMouseDown);
			bottom.x = 60;
			bottom.y = 10;
			this.addChild(bottom);
		}
		
		public function get textVAlign():String
		{
			return _textVAlign;
		}
		
		public function set textVAlign(value:String):void
		{
			_textVAlign = value;
			setVAlign(value);
		}
		
		private function setVAlign(value:String):void{
			if (this.at != null)
			{
				this.at.Mark(false);
			}
			switch(value){
				case TextVAlign.MIDDLE:
					this.at= middle;
					break;
				case TextVAlign.BOTTOM:
					this.at= bottom;
					break;
				default:
					this.at= top;
					break;
			}
			this.at.Mark(true);
		}
		
		private function ToolMouseDown(evt:MouseEvent):void{
			if (this.at != null)
			{
				this.at.Mark(false);
			}
			this.at=evt.currentTarget as ToolButton;
			switch(this.at.type){
				case ToolType.TextMiddle:
					this.baseOption.valign = TextVAlign.MIDDLE;
					break;
				case ToolType.TextBottom:
					this.baseOption.valign = TextVAlign.BOTTOM;
					break;
				default:
					this.baseOption.valign = TextVAlign.TOP;
					break;
			}
			this.baseOption.updateTextElemet();
			this.at.Mark(true);
		}
	}
}